package main

import (
	"fmt"
	"net/http"
	"time"
)

// main
//
//	@Description:
//
// 1.自定义handler结构体，实现Handler接口的ServeHTTP方法
//
// 2.使用server接口体，详细配置启动服务
func main() {

	//1.自定义handler结构体
	http.Handle("/handle", &MyHandler{})

	//2.使用server接口体，详细配置启动服务
	server := http.Server{
		Handler:      &MyHandler{},
		Addr:         ":8080",
		ReadTimeout:  10 * time.Second,
		WriteTimeout: 10 * time.Second,
		IdleTimeout:  10 * time.Second,
	}
	err := server.ListenAndServe()
	if err != nil {
		fmt.Println("ListenAndServe: ", err)
		return
	}

}

// MyHandler
// @Description: 自定义handler，实现Handler接口的ServeHTTP方法
type MyHandler struct {
}

// ServeHTTP
//
//	@Description:  实现Handler接口的ServeHTTP方法
//	@receiver h
//	@param writer
//	@param request
func (h *MyHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
	fmt.Fprintf(writer, "自定义hander,实现Handler接口的ServeHTTP方法    [path]:%s [content]: handler", request.URL.Path)
}
